package br.usp.icmc.biomac.client.view.impl;

import br.usp.icmc.biomac.client.view.ThumbnailCell;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ThumbnailCellImpl extends Composite implements ThumbnailCell {

	private static ThumbnailCellUiBinder uiBinder = GWT
			.create(ThumbnailCellUiBinder.class);
	@UiField Label labelRotulo;
	@UiField Label labelInfo;
	@UiField Image imgThumbnail;
	
	private Presenter presenter;

	interface ThumbnailCellUiBinder extends UiBinder<Widget, ThumbnailCellImpl> {
	}

	public ThumbnailCellImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	public ThumbnailCellImpl(String url, final String rotulo, String info) {
		initWidget(uiBinder.createAndBindUi(this));
		setImage(url);
		setRotulo(rotulo);
		setInfo(info);
		imgThumbnail.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				presenter.setImagesLoad(rotulo);
			}
		});
	}

	@Override
	public Widget asWidget() {
		return this;
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	public void setImage(String url){
		imgThumbnail.setUrl(url);
	}
	
	public void setRotulo(String rotulo){
		labelRotulo.setText(rotulo);
	}
	
	public void setInfo(String info){
		labelInfo.setText(info);
	}
}
